//
//  PayResultViewController.m
//  EastMarket
//
//  Created by 李鹏程 on 16/12/20.
//  Copyright © 2016年 guoguo. All rights reserved.
//

#import "PayResultViewController.h"

@interface PayResultViewController ()

@end

@implementation PayResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"订单创建完成";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *btnShare = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnShare setTitle:@"完成" forState:UIControlStateNormal];
    [btnShare addTarget:self action:@selector(orderFinished:) forControlEvents:UIControlEventTouchUpInside];
    [btnShare setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btnShare.frame = CGRectMake(0, 0, 42, 18);
    UIBarButtonItem *btnShareItem = [[UIBarButtonItem alloc] initWithCustomView:btnShare];
    [self.navigationItem setRightBarButtonItem:btnShareItem];
    
    UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnBack setBackgroundImage:[UIImage imageNamed:@"backbuttonWhite"]
                       forState:UIControlStateNormal];
    [btnBack addTarget:self action:@selector(backBBIDidOnClick) forControlEvents:UIControlEventTouchUpInside];
    btnBack.frame = CGRectMake(0, 0, 11.7, 20);
    btnBackItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
    self.navigationItem.leftBarButtonItem = btnBackItem;


    UIView *viewOrderInfo = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 6, TopBarHeight, SCREEN_WIDTH * 4 / 6, SCREEN_HEIGHT / 6)];
    viewOrderInfo.backgroundColor = [UIColor clearColor];
    [self.view addSubview:viewOrderInfo];
    UIImageView *imgMark = [[UIImageView alloc] initWithFrame:CGRectMake(0, (viewOrderInfo.frame.size.height - (viewOrderInfo.frame.size.width - 8) / 3) / 2, (viewOrderInfo.frame.size.width - 8) / 3, (viewOrderInfo.frame.size.width - 8) / 3)];
    imgMark.image = [UIImage imageNamed:@"myorder"];
    [viewOrderInfo addSubview:imgMark];
    
    UILabel *lblOrderSum = [[UILabel alloc] initWithFrame:CGRectMake(imgMark.frame.origin.x + 8 + imgMark.frame.size.width, imgMark.frame.origin.y, (viewOrderInfo.frame.size.width - 8) * 2 / 3, (imgMark.frame.size.height - 1) / 2)];
    lblOrderSum.text = [NSString stringWithFormat:@"订单数量: %ld个订单", _orderNum.integerValue];
    lblOrderSum.textColor = EastMarket_MainToneColor;
    lblOrderSum.font = [UIFont systemFontOfSize:14];
    NSMutableAttributedString *attributeStringSum = [[NSMutableAttributedString alloc] initWithString:lblOrderSum.text];
    [attributeStringSum setAttributes:@{NSForegroundColorAttributeName : EastMarket_darkGreyFontColor,   NSFontAttributeName : [UIFont systemFontOfSize:14]} range:NSMakeRange(0, 4)];
    
    lblOrderSum.attributedText = attributeStringSum;
    [viewOrderInfo addSubview:lblOrderSum];
    
    UILabel *lblOrderAmount = [[UILabel alloc] initWithFrame:CGRectMake(lblOrderSum.frame.origin.x, lblOrderSum.frame.origin.y + lblOrderSum.frame.size.height + 1, lblOrderSum.frame.size.width, lblOrderSum.frame.size.height)];
    lblOrderAmount.text = [NSString stringWithFormat:@"订单金额: ￥%.2lf", _strAmount.floatValue];
    lblOrderAmount.textColor = EastMarket_MainToneColor;
    lblOrderAmount.font = [UIFont systemFontOfSize:14];
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:lblOrderAmount.text];
    [attributeString setAttributes:@{NSForegroundColorAttributeName : EastMarket_darkGreyFontColor,   NSFontAttributeName : [UIFont systemFontOfSize:14]} range:NSMakeRange(0, 4)];
    lblOrderAmount.attributedText = attributeString;
    [viewOrderInfo addSubview:lblOrderAmount];
    
    UIView *viewBtn = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 6, viewOrderInfo.frame.origin.y + viewOrderInfo.frame.size.height + 8, SCREEN_WIDTH * 4 / 6, 32)];
    viewBtn.backgroundColor = [UIColor clearColor];
    [self.view addSubview:viewBtn];
    
    UIButton *btnMyOrder = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, (viewBtn.frame.size.width - 16) / 2, viewBtn.frame.size.height)];
    [btnMyOrder setTitle:@"我的订单" forState:UIControlStateNormal];
    [btnMyOrder setTitleColor:EastMarket_darkGreyFontColor forState:UIControlStateNormal];
    [btnMyOrder addTarget:self action:@selector(btnMyOrderClicked:) forControlEvents:UIControlEventTouchUpInside];
    btnMyOrder.layer.cornerRadius = 5.0f;
    btnMyOrder.layer.borderWidth = 1;
    btnMyOrder.layer.borderColor = [EastMarket_darkGreyFontColor CGColor];
    [viewBtn addSubview:btnMyOrder];
    
    UIButton *btnBackHomePage = [[UIButton alloc] initWithFrame:CGRectMake(btnMyOrder.frame.origin.x + btnMyOrder.frame.size.width + 16, 0, (viewBtn.frame.size.width - 16) / 2, viewBtn.frame.size.height)];
    [btnBackHomePage setTitle:@"返回首页" forState:UIControlStateNormal];
    [btnBackHomePage setTitleColor:EastMarket_darkGreyFontColor forState:UIControlStateNormal];
    [btnBackHomePage addTarget:self action:@selector(btnBackHomePageClicked:) forControlEvents:UIControlEventTouchUpInside];
    btnBackHomePage.layer.cornerRadius = 5.0f;
    btnBackHomePage.layer.borderWidth = 1;
    btnBackHomePage.layer.borderColor = [EastMarket_darkGreyFontColor CGColor];
    [viewBtn addSubview:btnBackHomePage];
}

- (void)backBBIDidOnClick {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)btnMyOrderClicked:(UIButton *)sender {

    MyOrderViewController *myOrderVC = [[MyOrderViewController alloc] init];
    [myOrderVC setHidesBottomBarWhenPushed:true];
    [self.navigationController pushViewController:myOrderVC animated:true];
}

- (void)btnBackHomePageClicked:(UIButton *)sender {

    [self.navigationController popToRootViewControllerAnimated:YES];
//    self.tabBarController.selectedIndex = 0;
}

- (void)orderFinished:(UIButton *)sender {

    MyOrderViewController *myOrderVC = [[MyOrderViewController alloc] init];
    [myOrderVC setHidesBottomBarWhenPushed:true];
    [self.navigationController pushViewController:myOrderVC animated:true];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
